//
//  AuthorizationSearchVc.m
//  MJApp
//
//  Created by John on 15/3/31.
//  Copyright (c) 2015年 wangliang. All rights reserved.
//

#import "AuthorizationSearchVc.h"

typedef enum {
    
    SideStateLeft,
    SideStateRight
    
}SideState;

@interface AuthorizationSearchVc ()
@property (weak, nonatomic) IBOutlet UITextField *authSearchtf;
@property (weak, nonatomic) IBOutlet UITextField *authCodeTf;

@end

@implementation AuthorizationSearchVc

- (id)addSiderView:(UIImage *)image  withSideState:(SideState)sideState withSide:(CGFloat)sideHeight withTag:(NSUInteger)tag {
    
    UIView * sideView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, image.size.width + sideHeight , image.size.height)];
    CGRect frame = CGRectMake(0, 0, image.size.width, image.size.height);
    if (sideState == SideStateLeft) {
        frame.origin.x = sideHeight;
    }else {
        
        frame.origin.x = sideHeight;
    }
    if (sideState == SideStateLeft) {
        
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
        [sideView addSubview:imageView];
        imageView.tag = tag;
        imageView.image = image;
    }else {
        
        UIButton *btn = [[UIButton alloc] initWithFrame:frame];
        [sideView addSubview:btn];
        btn.tag = tag;
        [btn setImage:image forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(check:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    return sideView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self UI];
    // Do any additional setup after loading the view from its nib.
}

- (void)UI {
    
    self.authSearchtf.placeholder = @"授权认证数查询";
    self.authCodeTf.placeholder = @"输入授权码";
    self.navigationItem.title = @"授权查询";
    
    UIImage *nameImage = [UIImage imageNamed:@"AuthSearch"];
    UIView *nameLeftView = [self addSiderView:nameImage withSideState:SideStateLeft withSide:10 withTag:1];
    self.view.backgroundColor = Color_Back_Black;
    self.authSearchtf.leftView = nameLeftView;
    self.authSearchtf.leftViewMode = UITextFieldViewModeAlways;
    
    
    UIImage *nameRightImage = [UIImage imageNamed:@"sq_01"];
    UIView *nameRightView = [self addSiderView:nameRightImage withSideState:SideStateRight withSide:0 withTag:2];
    self.authSearchtf.rightView = nameRightView;
    self.authSearchtf.rightViewMode = UITextFieldViewModeAlways;
    
    UIImage *seachImage = [UIImage imageNamed:@"sq_10"];
    UIView *seachLeftView = [self addSiderView:seachImage withSideState:SideStateLeft withSide:10 withTag:3];
    self.authCodeTf.leftView = seachLeftView;
    self.authCodeTf.leftViewMode = UITextFieldViewModeAlways;
    
    
    UIImage *seachRightImage = [UIImage imageNamed:@"sq_07"];
    UIView *seachRightView = [self addSiderView:seachRightImage withSideState:SideStateRight withSide:0 withTag:4];
    self.authCodeTf.rightView = seachRightView;
    self.authCodeTf.rightViewMode = UITextFieldViewModeAlways;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)check:(UIButton *)sender {
    NSMutableDictionary * param = [NSMutableDictionary dictionary];
    param[@"authorize"] = self.authCodeTf.text;
    
    [WLHTTPRequest checkPramaWithParam:param usingSucessBlock:^(BOOL isSucess, NSDictionary *resultDictionary) {
        if ([resultDictionary[@"status"] intValue]!=1) {
            [[DMCAlertCenter defaultCenter] postAlertWithMessage:resultDictionary[@"msg"]];
        }else{
         [[DMCAlertCenter defaultCenter] postAlertWithMessage:@"此店为正品授权店"];
        }
        
    } andFailureBlock:^(NSError *resultError) {
        
    }];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
